package list;

/**
 * Created with Intellij IDEA.
 * Description;
 * User:墨琦
 * Data:2023-04-11
 * Time:11:23
 */
public class ListNode {
    static class List {
    int val;
    List next;
    }
     public List head;

    public void addHead(int sum)
    {
        List kk=new List();
        kk.val=sum;
        if(head==null)
        {
            head=kk;
        }
        else{
            kk.next=head;
            head=kk;
        }
    }

    public  void show()
    {
        List kk=head;
        while(kk!=null)
        {
            System.out.print(kk.val+" ");
            kk=kk.next;
        }
        System.out.println(" ");
    }
    public ListNode.List reverseBetween (ListNode.List head, int m, int n) {

        List dummy = new List();
        dummy.next = head;
        List preStart = dummy;
        List start = head;
        for (int i = 1; i < m; i ++ ) {
            preStart = start;
            start = start.next;
        }
        // reverse
        for (int i = 0; i < n - m; i ++ ) {
            List temp = start.next;
            start.next = temp.next;
            temp.next = preStart.next;
            preStart.next = temp;
        }
        return dummy.next;
    }
    public void clear()
    {
       // head=null;
        List cur=head;

        while(cur!=null)
        {
            List curnext=cur.next;
            cur.next=null;
            cur=curnext;
        }
        head=null;
    }


}
